# coding:utf-8

from biquge.ThreadUtil import myThread
from biquge.util import getSoup

# 引入模块

# 要爬的地址

url = 'http://www.biquge.com.tw/quanben/'

soup = getSoup(url)

targe = soup.find(class_="l")

item_list = targe.find_all(class_="s2")

item_cotent_list = []

a_content_list = []

index_url = 'http://www.biquge.com.tw'

# 本地存放小说目录列表
path_list = []

# 小说章节URL列表
url_list = []

# 线程列表
thread_list = []

# 遍历页面元素并生成图片和小说
# for item in item_list:
#     img = item.find(class_="image").find("a").find("img")
#     img_src = img.attrs.get('src')
#     img_name = img.attrs.get('alt')
#     img_request = requests.get(img_src)
#
#     path = '/Users/wuxb/Documents/novel/'+img_name+"/"
#     mkdir(path)
#
#     #将目录存入列表方便线程使用
#     path_list.append(path)
#
#     #将url存入列表方便线程使用
#     url_list.append(item.find(class_="image").find("a").attrs.get('href'))
#
#     with open(path+img_name+".jpg",'wb') as f :
#         f.write(img_request.content)

for item in item_list:
    novel_url = item.find('a').get('href')
    novel_name = item.find('a').text

    path = '/Users/wuxb/Documents/novel/' + novel_name + "/"
    # mkdir(path)

    path_list.append(path)

    url_list.append(novel_url)


# range(len(item_list))

# 创建线程
for num in range(5, 6):
    xsThread = myThread(num, 'Thread-' + str(num), num, url_list, path_list, index_url)
    xsThread.start()
    thread_list.append(xsThread)

for t in thread_list:
    t.join()

print('结束')
